<?php

namespace App\Http\Controllers\Reception\Resources;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\URL;
use Illuminate\Http\Request;

//资源模块
class ResourcesController extends Controller
{
    public function getResources(Request $request)
    {
        $token = $request->query('token');
        //验证权限
        $verifytoken = verifytokens($token);
        if (is_array($verifytoken)) {
            return $verifytoken;
        }
        $page = (int) $request->query('page');
        $pageSize = (int) $request->query('pageSize');
        //翻页
        $page = $page - 1;
        if ($page != 0) {
            $page = $pageSize * $page;
            $pageSize = $pageSize * $page;
        }
        $info = DB::table('resources')
            ->orderByDesc("resources_create_time")
            ->offset($page)
            ->limit($pageSize)
            ->get();
        if ($info) {
            $data = success();
            $data['data'] = $info;
        } else {
            $data = fail();
        }
        return $data;
    }
}